﻿using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Common
{
    class SelectBuyPointDialogModel: IDisposable
    {
        private SqlCeDataReader _buyers;
        private SqlCeDataReader _buyPoint;

        public SelectBuyPointDialogModel()
        {
           WorkDataBase.GetInstance().Connection.Open();
        }

        public SqlCeDataReader GetBuyer()
        {
            string sqlQuery =
                "SELECT idBuyer, nameClient from Buyers";
            SqlCeCommand com = new SqlCeCommand(sqlQuery, WorkDataBase.GetInstance().Connection);
            _buyers = com.ExecuteReader();
            return _buyers;
        }

        public SqlCeDataReader GetBuyPoint (int id)
        {
            string sqlQuery =
                "SELECT BuyerId, NameBuyPoint, Adress from BuyPoints where BuyerId=@BuyerId";
            SqlCeCommand com = new SqlCeCommand(sqlQuery, WorkDataBase.GetInstance().Connection);
            com.Parameters.Add("@BuyerId", id);
            _buyPoint = com.ExecuteReader();
            return _buyPoint;
        }


        #region IDisposable Members

        public void Dispose()
        {
            WorkDataBase.GetInstance().Connection.Close();
        }

        #endregion
    }
}
